package com.longrise.co.ui.home.adapter;


import android.content.Context;
import android.widget.ImageView;
import android.widget.RatingBar;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.longrise.co.R;
import com.longrise.co.ui.home.model.CarCompany;
import com.ly.common.commonutils.ImageLoaderUtils;
import com.ly.common.commonutils.StringUtils;

import java.util.List;


/**
 * Created by admin on 2017/2/4.
 */

public class CarCompanyAdapter extends BaseQuickAdapter<CarCompany.ListBean> {
    private Context mContext;

    public CarCompanyAdapter(Context context, List<CarCompany.ListBean> listData) {
        super(R.layout.item_home_car_service, listData);
        mContext = context;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, CarCompany.ListBean data) {

        RatingBar rb = baseViewHolder.getView(R.id.ratingBar);
        if(data != null && !StringUtils.isEmpty(data.getEvaluatetotle())) {
            rb.setRating(Float.parseFloat(data.getEvaluatetotle()));
        }

        baseViewHolder.setText(R.id.title,  data.getCompanyname())
                .setText(R.id.address_tv, data.getCompanyaddress())
                .setText(R.id.ratingValue, data.getEvaluatetotle() + "分")
                .setText(R.id.distance_tv, "");

        ImageView imageView = baseViewHolder.getView(R.id.en_iv);

        if(!StringUtils.isEmpty(data.getCompanyimg())) {
            ImageLoaderUtils.display(mContext, imageView, data.getCompanyimg());
        }  else {
            imageView.setBackgroundResource(R.drawable.banner);
        }

    }


}
